﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Configuration;
using System.Reflection;
using StackOverflow.IDAL;

namespace StackOverflow.DalFactory
{
    //抽象工厂，负责Dal层创建

    public class AbstractFactory
    {
        private static readonly string AssemblyPath = ConfigurationManager.AppSettings["AssemplyPath"];
        private static readonly string NameSpace = ConfigurationManager.AppSettings["NameSpace"];


        /// <summary>
        /// 创建实体操作类
        /// </summary>
        /// <returns></returns>
        /// Author:bishisan
        /// Date:2017/8/31
        public static IUserInfoDal CreateUserInfoDal()
        {
            string fullClassName = NameSpace + ".UserInfoDal";
            return CreateInstance(fullClassName) as IUserInfoDal;
        }




        /// <summary>
        /// 通过映射创建数据操作类
        /// </summary>
        /// <param name="className">Name of the class.</param>
        /// <returns></returns>
        /// Author:bishisan
        /// Date:2017/8/31
        private static Object CreateInstance(string className)
        {
            var assemply = Assembly.Load(AssemblyPath);
            return assemply.CreateInstance(className);
        }
    }
}
